package com.zscat.mallplus.finance.service.impl;

import com.zscat.mallplus.finance.entity.FinanceCheck;
import com.zscat.mallplus.finance.entity.FinanceCheckAccount;
import com.zscat.mallplus.finance.entity.FinanceSettlement;
import com.zscat.mallplus.finance.mapper.FinanceCheckAccountMapper;
import com.zscat.mallplus.finance.mapper.FinanceCheckMapper;
import com.zscat.mallplus.finance.mapper.FinanceSettlementMapper;
import com.zscat.mallplus.finance.service.IFinanceSettlementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zscat.mallplus.finance.vo.CheckAmountDetailInfo;
import com.zscat.mallplus.oms.mapper.OmsOrderMapper;
import com.zscat.mallplus.sys.entity.SysStore;
import com.zscat.mallplus.sys.mapper.SysStoreMapper;
import com.zscat.mallplus.util.DateUtils;
import com.zscat.mallplus.util.UserUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author loop.fu
 * @since 2020-03-10
 */
@Service
public class FinanceSettlementServiceImpl extends ServiceImpl<FinanceSettlementMapper, FinanceSettlement> implements IFinanceSettlementService {

    @Resource
    private SysStoreMapper sysStoreMapper;

    @Resource
    private FinanceSettlementMapper financeSettlementMapper;

    @Resource
    private FinanceCheckAccountMapper financeCheckAccountMapper;

    @Resource
    private FinanceCheckMapper financeCheckMapper;

    @Override
    @Transactional
    public CheckAmountDetailInfo getCheckAmountDetailInfo(Long settlementId) {
        // 获取平台消息
        CheckAmountDetailInfo checkAmountDetailInfo = new CheckAmountDetailInfo();
        checkAmountDetailInfo.setPlatformAdress("广东省深圳市南山区创维大厦");
        checkAmountDetailInfo.setPlatformMobile("0755-86548995");
        checkAmountDetailInfo.setPlatformName("物连家美");
        // 获取商家信息
        SysStore systemStore = sysStoreMapper.selectById(UserUtils.getCurrentMember().getStoreId());
        checkAmountDetailInfo.setStoreAdress(systemStore.getCompanyAddress());
        checkAmountDetailInfo.setStoreMobile(systemStore.getSupportPhone());
        checkAmountDetailInfo.setStoreName(systemStore.getName());
        // 获取结算信息
        FinanceSettlement financeSettlement = financeSettlementMapper.selectById(settlementId);
        checkAmountDetailInfo.setStoreSettlementStartTime(DateUtils.format(financeSettlement.getStartTime(), "yyyy-MM-dd"));
        checkAmountDetailInfo.setStoreSettlementEndTime(DateUtils.format(financeSettlement.getEndTime(), "yyyy-MM-dd"));
        // 获取对账单金额信息
        FinanceCheck financeCheck = financeCheckMapper.selectById(financeSettlement.getCheckId());
        checkAmountDetailInfo.setTotalCheckAmount(financeCheck.getTotalSettleAmount());
        checkAmountDetailInfo.setTotalDiscountAmount(financeCheck.getTotalDiscountAmount());
        checkAmountDetailInfo.setTotalOrderAmount(financeCheck.getTotalOrderAmount());
        checkAmountDetailInfo.setTotalPayAmount(financeCheck.getTotalPayAmount());
        checkAmountDetailInfo.setTotalRefundAmount(financeCheck.getTotalRefundAmount());
        return checkAmountDetailInfo;
    }

}
